#include <bits/stdc++.h>
using namespace std;

int a[500005];

int main() {
	int n;
	long long ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] > a[i - 1]) {
			ans += a[i] - a[i - 1];
		}
	}
	cout << ans << endl;
	return 0;
}
